from datetime import datetime

from flask import Flask, request, jsonify, render_template
import interact# 导入您训练好的模型模块

app = Flask(__name__)
app.config['SECRET_KEY'] = 'your_secret_key'
 

# 模型预测API接口
@app.route('/api/predict', methods=['POST'])
def predict():
    try:
        data = request.get_json()
        if 'question' not in data or not data['question'].strip():
            return jsonify({'error': '请输入有效的医疗问题'}), 400

        # 调用您的模型预测函数
        answer = interact.model_predict(data['question'])

        return jsonify({
            'question': data['question'],
            'answer': answer,
            'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        })

    except Exception as e:
        return jsonify({'error': f'预测失败: {str(e)}'}), 500


# 主界面路由
@app.route('/')
def index():
    return render_template('index.html')


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)